package com.elong.businesstravel.modules.home.baseactivity;

import java.net.UnknownHostException;
import java.util.List;
import java.util.concurrent.TimeoutException;

import org.apache.http.Header;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.CompoundButton.OnCheckedChangeListener;

import com.android.support.jhf.debug.DebugLog;
import com.android.support.jhf.handlerui.HandlerPostUI;
import com.android.support.jhf.handlerui.HandlerToastUI;
import com.android.support.jhf.network.ErrorExceptionHandler;
import com.android.support.jhf.network.IErrorListener;
import com.android.support.jhf.network.NetworkClient;
import com.android.support.jhf.network.loopj.android.http.ResponseHandlerInterface;
import com.android.support.jhf.popupwindow.CustomPopupWindow;
import com.android.support.jhf.utils.AnimationUtils;
import com.android.support.jhf.utils.InputMethodUtils;
import com.android.support.jhf.utils.ToolUtils;
import com.baidu.platform.comapi.basestruct.GeoPoint;
import com.elong.businesstravel.R;
import com.elong.businesstravel.base.activity.BaseActivity;
import com.elong.businesstravel.base.activity.BaseMapActivity;
import com.elong.businesstravel.base.utils.SaveUserOperate;
import com.elong.businesstravel.base.utils.SettingsUtils;
import com.elong.businesstravel.base.view.TitleNavBarView;
import com.elong.businesstravel.entitys.Chains;
import com.elong.businesstravel.entitys.Hotel;
import com.elong.businesstravel.entitys.HotelNameSearchResult;
import com.elong.businesstravel.entitys.HotelSearchCondition;
import com.elong.businesstravel.entitys.MyGeoPoint;
import com.elong.businesstravel.entitys.Poi;
import com.elong.businesstravel.modules.home.HotelLocationSelectActivity;
import com.elong.businesstravel.modules.home.HotelSearchResultActivity;
import com.elong.businesstravel.modules.home.dialog.HotelBrandDialog;
import com.elong.businesstravel.modules.home.dialog.HotelPriceLevelDialog;
import com.elong.businesstravel.modules.home.dialog.HotelSortsDialog;
import com.elong.businesstravel.modules.home.view.SearchKeywordView;
import com.elong.businesstravel.protocol.city.GetCityChainRequest;
import com.elong.businesstravel.protocol.city.GetCityChainResponse;
import com.elong.businesstravel.protocol.hotel.GetHotelListRequest;
import com.elong.businesstravel.protocol.hotel.GetHotelListResponse;

public class BaseHotelResultActivity extends BaseMapActivity {

	protected static final String LIST = "列表";
	protected static final String MAP = "地图";

	protected String mActivityTag = LIST;

	protected static final int ANIMATION_DURATION = 200;

	protected Hotel mHotel = new Hotel();

	protected ViewGroup mSearchLayout;

	protected SearchKeywordView mSearchKeywordView;

	protected ViewGroup mSearchTopLayout;
	protected TextView mHotelNameTextView;
	protected ViewGroup mHotelNameLayout;

	protected HotelNameSearchResult hotelNameSearchResult;
	/** 用于标志是否显示排序 */
	protected boolean mSortByDistance;

	/** 当前页面用到的搜索条件，和全局的分开 */
	protected HotelSearchCondition mCurrentHotelSearchCondition;
	/** 酒店排序方式，附近酒店和选择酒店的排序方式不一样 */
	protected String[] mHotelSort;
	protected List<Chains> mChains;
	protected String mTitleString;

	protected MyGeoPoint mDestGeoPoint = null;

	protected TextView mLongClickTextView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	/**
	 * 只有地图返回到列表界面才调用
	 */
	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);

		setIntent(intent);
		mHotelSort = intent.getStringArrayExtra("sort");

		mCurrentHotelSearchCondition = (HotelSearchCondition) intent
				.getSerializableExtra("HotelSearchCondition");
		if (-1 == SettingsUtils.getHotelFull(mContext)) {
			mCurrentHotelSearchCondition.isfull = 1;
		} else {
			mCurrentHotelSearchCondition.isfull = SettingsUtils
					.getHotelFull(mContext);
		}
		mDestGeoPoint = (MyGeoPoint) getIntent().getSerializableExtra(
				"DestGeoPoint");
		mSearchKeywordView
				.setCurrentHotelSearchCondition(mCurrentHotelSearchCondition);

		mActivityTag = intent.getStringExtra("activityTag");
		if (null == mActivityTag) {
			mActivityTag = MAP;
		}

		if (null != mCurrentHotelSearchCondition
				|| !TextUtils.isEmpty(mCurrentHotelSearchCondition.keyword)) {
			mHotelNameLayout.setVisibility(View.VISIBLE);
			mHotelNameTextView.setVisibility(View.VISIBLE);
			mSearchKeywordView
					.setDefaultSearchText(mCurrentHotelSearchCondition.keyword);
			mHotelNameTextView.setText(mCurrentHotelSearchCondition.keyword);
		} else {
			mSearchTopLayout.setVisibility(View.VISIBLE);
			mHotelNameLayout.setVisibility(View.GONE);
			mHotelNameTextView.setVisibility(View.GONE);
			mHotelNameTextView.setText("");
		}
	}

	@Override
	protected void init() {
		mHotelSort = getIntent().getStringArrayExtra("sort");

		mActivityTag = getIntent().getStringExtra("activityTag");
		if (null == mActivityTag) {
			mActivityTag = MAP;
		}

		mSearchLayout = (ViewGroup) findViewById(R.id.searchLayout);
		mSearchKeywordView = (SearchKeywordView) findViewById(R.id.searchKeywordView);
		mSearchKeywordView.setVisibility(View.GONE);
		mSearchKeywordView
				.setCurrentHotelSearchCondition(mCurrentHotelSearchCondition);

		// mSearchTextView = (TextView) findViewById(R.id.searchTextView);
		mSearchTopLayout = (ViewGroup) findViewById(R.id.searchTopLayout);
		mHotelNameTextView = (TextView) findViewById(R.id.hotelNameTextView);
		mHotelNameLayout = (ViewGroup) findViewById(R.id.hotelNameLayout);
		mHotelNameLayout.setVisibility(View.GONE);
		mHotelNameTextView.setVisibility(View.GONE);

		setTitleNavBar();

		if (!TextUtils.isEmpty(mCurrentHotelSearchCondition.keyword)) {
			mHotelNameLayout.setVisibility(View.VISIBLE);
			mHotelNameTextView.setVisibility(View.VISIBLE);
			mSearchKeywordView
					.setDefaultSearchText(mCurrentHotelSearchCondition.keyword);
			mHotelNameTextView.setText(mCurrentHotelSearchCondition.keyword);
		} else {
			mHotelNameLayout.setVisibility(View.GONE);
			mHotelNameTextView.setVisibility(View.GONE);
			mHotelNameTextView.setText("");
		}

		// getHotelList(false);

	}

	@Override
	protected void setListener() {
		mSearchKeywordView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				hotelNameSearchResult = mSearchKeywordView
						.getHotelNameSearchResultForIndex(position);

				getHotelListForSearchResult(false, hotelNameSearchResult);

				mSearchKeywordView.setVisibility(View.GONE);
				if (null != mLongClickTextView)
				mLongClickTextView.setVisibility(View.VISIBLE);

			}
		});
		mSearchKeywordView.setSearchOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				hotelNameSearchResult = null;

				String keyword = (String) v.getTag();
				mCurrentHotelSearchCondition.keyword = keyword;
				mSearchKeywordView.setVisibility(View.GONE);
				if (null != mLongClickTextView)
				mLongClickTextView.setVisibility(View.VISIBLE);
				mCurrentHotelSearchCondition.sorts = -1;

				getHotelListForSearchResult(false, hotelNameSearchResult);
			}
		});

		mSearchLayout.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (View.VISIBLE == mSearchKeywordView.getVisibility()) {
					return;
				}
				mSearchKeywordView.setVisibility(View.VISIBLE);
				if (null != mLongClickTextView)
					mLongClickTextView.setVisibility(View.GONE);
				Animation animation = AnimationUtils.alpha(0.0F, 1.0F,
						ANIMATION_DURATION, new AnimationListener() {

							@Override
							public void onAnimationStart(Animation animation) {

							}

							@Override
							public void onAnimationEnd(Animation animation) {
								mSearchKeywordView.setVisibility(View.VISIBLE);
								if (null != hotelNameSearchResult
										&& !TextUtils
												.isEmpty(hotelNameSearchResult.hotelName)) {
									mSearchKeywordView
											.setDefaultSearchText(hotelNameSearchResult.hotelName);
								} else if (!TextUtils
										.isEmpty(mCurrentHotelSearchCondition.keyword)) {
									mSearchKeywordView
											.setDefaultSearchText(mCurrentHotelSearchCondition.keyword);
								}
								mSearchKeywordView.setEditTextFocus();
								mSearchKeywordView.clearAnimation();
							}

							@Override
							public void onAnimationRepeat(Animation animation) {

							}

						});
				mSearchKeywordView.startAnimation(animation);
			}
		});

		Button sortsButton = (Button) findViewById(R.id.sortsButton);
		sortsButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (View.VISIBLE == mSearchKeywordView.getVisibility()) {
					cancelSearchKeyworkView();
				} else {
					hotelSortDialog();
				}
			}
		});
		Button brandButton = (Button) findViewById(R.id.brandButton);
		brandButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (View.VISIBLE == mSearchKeywordView.getVisibility()) {
					cancelSearchKeyworkView();
				} else {
					goHotelBrandDialog();
				}
			}
		});
		Button locationButton = (Button) findViewById(R.id.locationButton);
		locationButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (View.VISIBLE == mSearchKeywordView.getVisibility()) {
					cancelSearchKeyworkView();
				} else {
					Intent intent = new Intent(mContext,
							HotelLocationSelectActivity.class);
					intent.putExtra("city",
							mCurrentHotelSearchCondition.mSearchConditionCity);
					startActivityForResult(intent, 2);
					overridePendingTransition(
							R.anim.activity_bottom_top_enter_anim_translate,
							R.anim.activity_alpha_fixed);
				}
			}
		});
		Button priceButton = (Button) findViewById(R.id.priceButton);
		priceButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (View.VISIBLE == mSearchKeywordView.getVisibility()) {
					cancelSearchKeyworkView();
				} else {
					hotelPriceLevelDialog();
				}
			}
		});
	}

	private void hotelSortDialog() {
		final HotelSortsDialog hotelSortsDialog = new HotelSortsDialog(
				mContext, com.android.support.jhf.R.style.DialogFromDownToUp,
				mHotelSort, mCurrentHotelSearchCondition.sorts);
		hotelSortsDialog.setOnItemListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {

				mCurrentHotelSearchCondition.sorts = arg2;
				getHotelList(false);
				hotelSortsDialog.cancel();
			}
		});
		hotelSortsDialog.show();
	}

	private void goHotelBrandDialog() {
		if (null == mChains || 0 == mChains.size()) {
			getCityChain(mCurrentHotelSearchCondition.mSearchConditionCity.cityId);
		} else {
			hotelBrandDialog();
		}
	}

	private void hotelBrandDialog() {
		final HotelBrandDialog hotelBrandDialog = new HotelBrandDialog(
				mContext, com.android.support.jhf.R.style.DialogFromDownToUp,
				mChains, mCurrentHotelSearchCondition.chainId);
		hotelBrandDialog.setOnItemListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {

				Chains chains = mChains.get(arg2);
				if ("不限".equals(chains.shortname)) {
					mCurrentHotelSearchCondition.chainId = "";
				} else {
					mCurrentHotelSearchCondition.chainId = chains.brandid;
				}
				getHotelList(false);

				hotelBrandDialog.cancel();

			}
		});
		hotelBrandDialog.show();
	}

	private void hotelPriceLevelDialog() {
		final HotelPriceLevelDialog hotelPriceLevelDialog = new HotelPriceLevelDialog(
				mContext, com.android.support.jhf.R.style.DialogFromDownToUp,
				mCurrentHotelSearchCondition.mSearchConditionPriceValuePosition);
		hotelPriceLevelDialog.setOnItemListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {

				mCurrentHotelSearchCondition.mSearchConditionPriceValuePosition = arg2;

				getHotelList(false);

				hotelPriceLevelDialog.cancel();

			}
		});
		hotelPriceLevelDialog.show();
	}

	@Override
	protected void setTitleNavBar() {

		if (1 == mCurrentHotelSearchCondition.isfull) {
			mTitleString = "全部酒店";
		} else if (0 == mCurrentHotelSearchCondition.isfull) {
			mTitleString = "不展示满房";
		}
		final TitleNavBarView titleNavBarView = (TitleNavBarView) findViewById(R.id.titleNavBarView);
		titleNavBarView.setMessageRightArrowOnClickListener(mTitleString,
				R.drawable.ic_arrow_bottom, new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						DebugLog.logI("全部酒店");
						showPopupWindow(titleNavBarView);
					}
				});
		titleNavBarView.setLeftDrawableImage(R.drawable.btn_title_back);
		titleNavBarView.setLeftButtonImageString(0, "返回", R.color.text_blue);
		titleNavBarView.setLeftButtonOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (View.VISIBLE == mSearchKeywordView.getVisibility()) {
					cancelSearchKeyworkView();
				} else {
					titleLeftOnClick(mActivityTag);
				}
			}
		});
		titleNavBarView.setRightButtonImageString(0, mActivityTag,
				R.color.text_blue);
		titleNavBarView
				.setRightButtonOnClickListener(new com.android.support.jhf.onClick.OnClickListener() {

					@Override
					public void onFastDoubleClick(View view) {
						if (View.VISIBLE == mSearchKeywordView.getVisibility()) {
							cancelSearchKeyworkView();
						} else {
							titleRightOnClick(mActivityTag);
						}
					}
				});
	}

	private void showPopupWindow(View anchor) {
		View view = LayoutInflater.from(mContext).inflate(
				R.layout.view_manfang, null);
		final CustomPopupWindow customPopupWindow = new CustomPopupWindow(
				mContext);
		customPopupWindow.setContentView(view,
				ToolUtils.dipToPx(mContext, 154),
				ToolUtils.dipToPx(mContext, 106));
		customPopupWindow
				.show(anchor,
						anchor.getWidth() / 2
								- ToolUtils.dipToPx(mContext, 154) / 2, 0);
		TextView allHotelTextView = (TextView) view
				.findViewById(R.id.allHotelTextView);
		allHotelTextView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// mTitleString = "全部酒店";
				mCurrentHotelSearchCondition.isfull = 1;
				SettingsUtils.setHotelFull(mContext, 1);
				setTitleNavBar();
				customPopupWindow.dismiss();
				getHotelList(false);
			}
		});
		TextView noShowManFangTextView = (TextView) view
				.findViewById(R.id.noShowManFangTextView);
		noShowManFangTextView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// mTitleString = "不展示满房";
				mCurrentHotelSearchCondition.isfull = 0;
				SettingsUtils.setHotelFull(mContext, 0);
				setTitleNavBar();
				customPopupWindow.dismiss();
				getHotelList(false);
			}
		});
	}

	protected void getHotelListForSearchResult(final boolean moreFlag,
			HotelNameSearchResult hotelNameSearchResult) {

		mCurrentHotelSearchCondition.mSearchConditionPriceValuePosition = 0;
		mCurrentHotelSearchCondition.mSearchConditionPoi = new Poi();
		mCurrentHotelSearchCondition.sorts = -1;
		if (null != hotelNameSearchResult) {
			if (!TextUtils.isEmpty(hotelNameSearchResult.bussinename)) {
				mCurrentHotelSearchCondition.mSearchConditionPoi.googlelat = null;
				mCurrentHotelSearchCondition.mSearchConditionPoi.googlelng = null;
				mCurrentHotelSearchCondition.piloting = null;

				Poi poi = new Poi();
				poi.bussinesid = hotelNameSearchResult.bussinesid;
				// mCurrentHotelSearchCondition.districtsId = null;
				// mCurrentHotelSearchCondition.bussinesId =
				// hotelNameSearchResult.bussinesid;
				mCurrentHotelSearchCondition.mSearchConditionPoi = poi;
				mCurrentHotelSearchCondition.chainId = null;
				mCurrentHotelSearchCondition.keyword = null;

				// mCurrentHotelSearchCondition.sorts = 4;
			} else if (!TextUtils.isEmpty(hotelNameSearchResult.hotelName)) {
				mCurrentHotelSearchCondition.mSearchConditionPoi.googlelat = null;
				mCurrentHotelSearchCondition.mSearchConditionPoi.googlelng = null;
				mCurrentHotelSearchCondition.piloting = hotelNameSearchResult.hotelName;

				// mCurrentHotelSearchCondition.districtsId = null;
				// mCurrentHotelSearchCondition.bussinesId = null;
				mCurrentHotelSearchCondition.chainId = null;
				mCurrentHotelSearchCondition.keyword = hotelNameSearchResult.hotelName;
				// mCurrentHotelSearchCondition.sorts = 4;
			} else if (!TextUtils.isEmpty(hotelNameSearchResult.name)) {
				mCurrentHotelSearchCondition.mSearchConditionPoi.googlelat = Double
						.parseDouble(hotelNameSearchResult.googlelat);
				mCurrentHotelSearchCondition.mSearchConditionPoi.googlelng = Double
						.parseDouble(hotelNameSearchResult.googlelng);
				mCurrentHotelSearchCondition.piloting = hotelNameSearchResult.name;

				// mCurrentHotelSearchCondition.districtsId = null;
				// mCurrentHotelSearchCondition.bussinesId = null;
				// mCurrentHotelSearchCondition.sorts = 4;
				mCurrentHotelSearchCondition.chainId = null;

			} else if (!TextUtils.isEmpty(hotelNameSearchResult.shortname)) {
				mCurrentHotelSearchCondition.chainId = hotelNameSearchResult.brandid;
				mCurrentHotelSearchCondition.mSearchConditionPoi.googlelat = null;
				mCurrentHotelSearchCondition.mSearchConditionPoi.googlelng = null;
				mCurrentHotelSearchCondition.piloting = null;

				// mCurrentHotelSearchCondition.districtsId = null;
				// mCurrentHotelSearchCondition.bussinesId = null;
				mCurrentHotelSearchCondition.keyword = null;

				// mCurrentHotelSearchCondition.sorts = 4;
			} else if (!TextUtils.isEmpty(hotelNameSearchResult.districtsname)) {
				mCurrentHotelSearchCondition.mSearchConditionPoi.googlelat = null;
				mCurrentHotelSearchCondition.mSearchConditionPoi.googlelng = null;
				mCurrentHotelSearchCondition.piloting = null;

				Poi poi = new Poi();
				poi.districtsid = hotelNameSearchResult.districtsid;
				mCurrentHotelSearchCondition.mSearchConditionPoi = poi;
				// mCurrentHotelSearchCondition.districtsId =
				// hotelNameSearchResult.districtsid;
				// mCurrentHotelSearchCondition.bussinesId = null;
				mCurrentHotelSearchCondition.chainId = null;
				mCurrentHotelSearchCondition.keyword = null;

				// mCurrentHotelSearchCondition.sorts = 4;
			}
		} else {
			mCurrentHotelSearchCondition.piloting = mCurrentHotelSearchCondition.keyword;
		}
		getHotelList(moreFlag);
	}

	/**
	 * 在地图界面长按选择目的地
	 * 
	 * @param moreFlag
	 * @param lat
	 * @param lng
	 */
	protected void getHotlList(final boolean moreFlag, Double lat, Double lng) {

		mCurrentHotelSearchCondition.sorts = 4;
		mHotelSort = mApplication.mHotelLocSorts;

		mCurrentHotelSearchCondition.chainId = null;
		mCurrentHotelSearchCondition.mSearchConditionPoi.bussinesid = null;
		mCurrentHotelSearchCondition.mSearchConditionPoi.districtsid = null;
		mCurrentHotelSearchCondition.mSearchConditionPoi.googlelat = null;
		mCurrentHotelSearchCondition.mSearchConditionPoi.googlelng = null;
		mCurrentHotelSearchCondition.keyword = null;

		// mCurrentHotelSearchCondition.sorts = Integer
		// .parseInt(getIntent().getStringExtra("sorts"));
		Poi poi = new Poi();
		poi.name = "目的地";
		poi.googlelat = lat;
		poi.googlelng = lng;
		mCurrentHotelSearchCondition.mSearchConditionPoi = poi;

		getHotelList(moreFlag,
				mCurrentHotelSearchCondition.mSearchConditionCity.cityId,
				mCurrentHotelSearchCondition.getStartDate(),
				mCurrentHotelSearchCondition.getEndDate(),
				mCurrentHotelSearchCondition.getMinPrice(mContext),
				mCurrentHotelSearchCondition.getMaxPrice(mContext),
				mCurrentHotelSearchCondition.getStar(mContext),
				mCurrentHotelSearchCondition.chainId,
				mCurrentHotelSearchCondition.mSearchConditionPoi.bussinesid,
				mCurrentHotelSearchCondition.mSearchConditionPoi.districtsid,
				mCurrentHotelSearchCondition.mSearchConditionPoi.googlelat,
				mCurrentHotelSearchCondition.mSearchConditionPoi.googlelng,
				mCurrentHotelSearchCondition.keyword,
				mCurrentHotelSearchCondition.pageSize,
				mCurrentHotelSearchCondition.sorts,
				mCurrentHotelSearchCondition.product,
				mCurrentHotelSearchCondition.isfull,
				mCurrentHotelSearchCondition.uid,
				mCurrentHotelSearchCondition.deviceId,
				mCurrentHotelSearchCondition.token);
	}

	protected void getHotelList(final boolean moreFlag) {
		getHotelList(moreFlag,
				mCurrentHotelSearchCondition.mSearchConditionCity.cityId,
				mCurrentHotelSearchCondition.getStartDate(),
				mCurrentHotelSearchCondition.getEndDate(),
				mCurrentHotelSearchCondition.getMinPrice(mContext),
				mCurrentHotelSearchCondition.getMaxPrice(mContext),
				mCurrentHotelSearchCondition.getStar(mContext),
				mCurrentHotelSearchCondition.chainId,
				mCurrentHotelSearchCondition.mSearchConditionPoi.bussinesid,
				mCurrentHotelSearchCondition.mSearchConditionPoi.districtsid,
				mCurrentHotelSearchCondition.mSearchConditionPoi.googlelat,
				mCurrentHotelSearchCondition.mSearchConditionPoi.googlelng,
				mCurrentHotelSearchCondition.keyword,
				mCurrentHotelSearchCondition.pageSize,
				mCurrentHotelSearchCondition.sorts,
				mCurrentHotelSearchCondition.product,
				mCurrentHotelSearchCondition.isfull,
				mCurrentHotelSearchCondition.uid,
				mCurrentHotelSearchCondition.deviceId,
				mCurrentHotelSearchCondition.token);
	}

	private void getHotelList(final boolean moreFlag, String cityId,
			String startDate, String endDate, String minPrice,
			String maxpPrice, String star, String chainId, String bussinesId,
			String districtsId, Double lat, Double lng, String keyword,
			Integer pageSize, Integer sorts, Integer product, Integer isfull,
			Integer uid, String deviceId, String token) {

		if (moreFlag) {
			mCurrentHotelSearchCondition.page = mCurrentHotelSearchCondition.page + 1;
		} else {
			mCurrentHotelSearchCondition.page = 1;
		}

		NetworkClient.getNetworkClient().PostRequest(
				new GetHotelListRequest(mContext, cityId, startDate, endDate,
						minPrice, maxpPrice, star, chainId, bussinesId,
						districtsId, lat, lng, keyword, pageSize,
						mCurrentHotelSearchCondition.page, sorts, product,
						isfull, uid, deviceId, token),
				new GetHotelListResponse() {
					@Override
					public void onResponse(
							final ResponseHandlerInterface responseHandlerInterface) {
						HandlerPostUI.getHandlerPostUI(new Runnable() {

							@Override
							public void run() {
								Hotel hotel = ((GetHotelListResponse) responseHandlerInterface).hotel;
								mHotel.lat = hotel.lat;
								mHotel.lng = hotel.lng;
								mHotel.numFound = hotel.numFound;
								mHotel.pageCount = hotel.pageCount;
								mHotel.start = hotel.start;
								mHotel.prehotel = hotel.prehotel;
								// boolean sortByDistance = false;
								if ("null".equals(hotel.lng)
										|| TextUtils.isEmpty(hotel.lng)
										|| "null".equals(hotel.lat)
										|| TextUtils.isEmpty(hotel.lat)) {
									// sortByDistance = false;
									mSortByDistance = false;
								} else {
									// sortByDistance = true;
									mSortByDistance = true;
								}
								if (moreFlag) {
									// 更多
									if (0 == hotel.mHotelDocs.size()) {

										HandlerToastUI.getHandlerToastUI(
												mContext, "没有更多酒店");
									} else {
										mHotel.mHotelDocs
												.addAll(hotel.mHotelDocs);
									}
								} else {
									// 刷新
									mHotel.mHotelDocs.clear();
									mHotel.mHotelDocs.addAll(hotel.mHotelDocs);
								}
								updateHotelDate(mSortByDistance);
							}
						});

					}
				}, null, new IErrorListener() {

					@Override
					public void onFailure(int statusCode, Header[] headers,
							byte[] responseBody, Throwable error) {
						StringBuffer errorString = new StringBuffer();
						ErrorExceptionHandler.NetworkExceptionHandler(
								errorString, error);
						if (!TextUtils.isEmpty(errorString.toString())) {
							HandlerToastUI.getHandlerToastUI(mContext,
									errorString.toString());
						}
						BaseHotelResultActivity.this.onFailure(statusCode,
								headers, responseBody, error);
					}
				});
	}

	protected void onFailure(int statusCode, Header[] headers,
			byte[] responseBody, Throwable error) {

	}

	/**
	 * 更新酒店数据，列表地图等
	 * 
	 * @param sortByDistance
	 *            true返回带坐标按照距离排序，false返回不带坐标默认排序
	 */
	protected void updateHotelDate(boolean sortByDistance) {

	}

	/**
	 * 标题右边按钮点击
	 * 
	 * @param textString
	 */
	protected void titleRightOnClick(String textString) {

	}

	/**
	 * 标题左边按钮点击
	 * 
	 * @param textString
	 */
	protected void titleLeftOnClick(String textString) {

	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		switch (requestCode) {
		case 0: {
			// 排序返回
			switch (resultCode) {
			case RESULT_OK: {
				int sorts = data.getIntExtra("sorts", 0);
				mCurrentHotelSearchCondition.sorts = sorts;
				getHotelList(false);
				break;
			}
			case RESULT_CANCELED: {
				break;
			}
			default:
				break;
			}
			break;
		}
		case 1: {
			// 品牌返回
			switch (resultCode) {
			case RESULT_OK: {
				Chains chains = (Chains) data.getSerializableExtra("chains");
				mCurrentHotelSearchCondition.chainId = chains.brandid;
				getHotelList(false);
				break;
			}
			case RESULT_CANCELED: {
				break;
			}
			default:
				break;
			}
			break;
		}
		case 2: {
			// 选择位置返回
			switch (resultCode) {
			case RESULT_OK: {
				mCurrentHotelSearchCondition.mSearchConditionPoi = (Poi) data
						.getSerializableExtra("Poi");
				String nameString = mCurrentHotelSearchCondition.mSearchConditionPoi.name;
				if ("".equals(nameString)) {
					nameString = mCurrentHotelSearchCondition.mSearchConditionPoi.bussinename;
				}
				if ("".equals(nameString)) {
					nameString = mCurrentHotelSearchCondition.mSearchConditionPoi.districtsname;
				}

				// 清空搜索框
				mCurrentHotelSearchCondition.keyword = null;
				mCurrentHotelSearchCondition.piloting = null;

				if ("当前位置".equals(nameString)
						|| (mCurrentHotelSearchCondition.mSearchConditionPoi.googlelat != null && mCurrentHotelSearchCondition.mSearchConditionPoi.googlelat != 0.0D)
						|| (mCurrentHotelSearchCondition.mSearchConditionPoi.googlelng != null && mCurrentHotelSearchCondition.mSearchConditionPoi.googlelng != 0.0D)) {
					mCurrentHotelSearchCondition.sorts = 4;
					mHotelSort = mApplication.mHotelLocSorts;
				} else {
					mCurrentHotelSearchCondition.sorts = 0;
					mHotelSort = mApplication.mHotelSorts;
				}
				getHotelList(false);

				break;
			}
			case RESULT_CANCELED: {
				break;
			}
			default:
				break;
			}
			break;
		}
		case 3: {
			// 选择价格/星级
			switch (resultCode) {
			case RESULT_OK: {
				mCurrentHotelSearchCondition.mSearchConditionPriceValuePosition = data
						.getIntExtra("priceLevelValuePosition", 0);

				// mPriceTextView
				// .setText(mApplication.mPriceLevel[mCurrentHotelSearchCondition.mSearchConditionPriceValuePosition]);
				getHotelList(false);
				break;
			}
			case RESULT_CANCELED: {
				break;
			}
			default:
				break;
			}
			break;
		}
		default:
			break;
		}
	}

	/**
	 * 获取城市快捷酒店
	 * 
	 * @param cityId
	 */
	private void getCityChain(String cityId) {

		NetworkClient.getNetworkClient().PostRequest(
				new GetCityChainRequest(mContext, cityId),
				new GetCityChainResponse() {
					@Override
					public void onResponse(
							ResponseHandlerInterface responseHandlerInterface) {

						mChains = ((GetCityChainResponse) responseHandlerInterface).chains;

						Chains chains = new Chains();
						chains.shortname = "不限";
						chains.brandid = "";
						mChains.add(0, chains);

						HandlerPostUI.getHandlerPostUI(new Runnable() {

							@Override
							public void run() {
								hotelBrandDialog();
							}
						});
					}
				});
	}

	/**
	 * 关闭SearchKeywordView
	 */
	private void cancelSearchKeyworkView() {
		if (View.VISIBLE == mSearchKeywordView.getVisibility()) {
			mSearchKeywordView.setVisibility(View.GONE);
			if (null != mLongClickTextView)
			mLongClickTextView.setVisibility(View.VISIBLE);
			Animation animation = AnimationUtils.alpha(1.0F, 0.0F,
					ANIMATION_DURATION, new AnimationListener() {

						@Override
						public void onAnimationStart(Animation animation) {

						}

						@Override
						public void onAnimationEnd(Animation animation) {
							mSearchKeywordView.setVisibility(View.GONE);
							if (null != mLongClickTextView)
							mLongClickTextView.setVisibility(View.VISIBLE);
							mSearchKeywordView.clearAnimation();
							InputMethodUtils.hideSoftKeyboard(mContext,
									mSearchKeywordView.getEditTextClearView()
											.getEditText());
						}

						@Override
						public void onAnimationRepeat(Animation animation) {

						}

					});
			mSearchKeywordView.startAnimation(animation);
		} else {

		}
	}

	@Override
	public boolean onKeyDown(int keyCode, android.view.KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			if (View.VISIBLE == mSearchKeywordView.getVisibility()) {
				cancelSearchKeyworkView();
				return true;
			} else {

			}
		}
		return super.onKeyDown(keyCode, event);
	}
}
